000100*****************************************************************
000200*PROGRAM : Student Inquiry
000300*AUTHOR  : Minh-Tuan Ta
000400*****************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. STU-I.
000700 ENVIRONMENT DIVISION.
000800     SELECT INFILE   ASSIGN TO "STUMST.DAT"
000900                     ORGANIZATION    IS  INDEXED
001000                     ACCESS          IS  DYNAMIC
001100                     RECORD KEY      IS  IN-STU-ID
001200                     ALTERNATE KEY IS IN-LNAME WITH DUPLICATES
001300                     FILE STATUS     IS  WS-STAT.
001400
001500     SELECT INZIP    ASSIGN TO "ZIPFILE.DAT"
001600                     ORGANIZATION    IS INDEXED
001700                     ACCESS          IS DYNAMIC
001800                     RECORD KEY      IS ZIPCODE
001900                     ALTERNATE KEY IS ZIP-CITY WITH DUPLICATES
002000                     FILE STATUS IS WS-STAT.
002100 DATA DIVISION.
002200 FILE SECTION.
002300 FD  INFILE.
002400 01  IN-REC.
002500     03  IN-STU-ID           PIC 9(4).
002600     03  IN-FNAME            PIC X(20).
002700     03  IN-LNAME            PIC X(20).
002800     03  IN-STREET           PIC X(30).
002900     03  IN-ZIP              PIC X(5).
003000     03  IN-ACTIVE           PIC X.
003100
003200 FD  INZIP.
003300 01  ZIP-REC.
003400     03  ZIPCODE             PIC X(5).
003500     03  ZIP-CITY            PIC X(30).
003600     03  ZIP-STATE           PIC X(2).
003700     03  ZIP-COUNTY          PIC X(30).
003800
003900 WORKING-STORAGE SECTION.
004000 01  WS-VARS.
004100     03  WS-DATE.
004200         05  WS-YEAR         PIC 99.
004300         05  WS-MONTH        PIC 99.
004400         05  WS-DAY          PIC 99.
004500     03  WS-STU-ID           PIC 9(4).
004600     03  WS-STAT             PIC X(2).
004700     03  WS-CONTINUE         PIC X.
004800     03  WS-EOF              PIC X   VALUE "N".
004900     03  WS-LOOP-CNT         PIC 99  VALUE ZEROS.
005000     03  WS-CNT              PIC 999 VALUE ZEROS.
005100     03  WS-INQ-TYPE         PIC X.
005200     03  WS-LNAME            PIC X(20).
005300     03  WS-ERR              PIC X.
005400 01  OUT-ARRAY.
005500 03  OUT-RECORDS OCCURS 20 TIMES.
005600     05  OUT-NO              PIC 9(3).
005700     05  FILLER              PIC X VALUE SPACES.
005800     05  OUT-STU-ID          PIC 9(4).
005900     05  FILLER              PIC X VALUE SPACES.
006000     05  OUT-FNAME           PIC X(20).
006100     05  FILLER              PIC X VALUE SPACES.
006200     05  OUT-LNAME           PIC X(20).
006300     05  FILLER              PIC X VALUE SPACES.
006400     05  OUT-ZIP             PIC X(5).
006500     05  FILLER              PIC X VALUE SPACES.
006600     05  OUT-ACTIVE          PIC X.
006700 SCREEN SECTION.
006800 01  INQ-TYPE-SCRN.
006900     03  BLANK SCREEN.
007000     03  MENU.
007100         05  LINE 1  COL 01  VALUE "STUDENT INQUIRY".
007200         05          COL 73  PIC 9(2) FROM WS-MONTH.
007300         05          COL 75  VALUE "/".
007400         05          COL 76  PIC 9(2) FROM WS-DAY.
007500         05          COL 78  VALUE "/".
007600         05          COL 79  PIC 9(2) FROM WS-YEAR.
007700         05  LINE 2  COL 37  VALUE "INQUIRY BY".
007800         05  LINE 4  COL 20  VALUE "1 STUDENT ID".
007900         05  LINE 5  COL 20  VALUE "2 STUDENT LAST NAME".
008000         05  LINE 7  COL 22  VALUE "PICK YOUR KIND OF INQUIRY".
008100         05  LINE 7  COL 20  PIC X TO WS-INQ-TYPE AUTO.
008200         05  LINE 11 COL 20  VALUE "ENTER X TO EXIT".
008300
008400 01  ENTER-STU-ID-SCRN.
008500     03  BLANK SCREEN.
008600     03  MENU.
008700         05  LINE 1  COL 01  VALUE "STUDENT INQUIRY".
008800         05          COL 73  PIC 9(2) FROM WS-MONTH.
008900         05          COL 75  VALUE "/".
009000         05          COL 76  PIC 9(2) FROM WS-DAY.
009100         05          COL 78  VALUE "/".
009200         05          COL 79  PIC 9(2) FROM WS-YEAR.
009300         05  LINE 2  COL 37  VALUE "ENTER STUDENT ID".
009400         05  LINE 4  COL 37  PIC 9(4) TO WS-STU-ID AUTO.
009500
009600 01  ENTER-LNAME-SCRN.
009700     03  BLANK SCREEN.
009800     03  MENU.
009900         05  LINE 1  COL 01  VALUE "STUDENT INQUIRY".
010000         05          COL 73  PIC 9(2) FROM WS-MONTH.
010100         05          COL 75  VALUE "/".
010200         05          COL 76  PIC 9(2) FROM WS-DAY.
010300         05          COL 78  VALUE "/".
010400         05          COL 79  PIC 9(2) FROM WS-YEAR.
010500         05  LINE 2  COL 37  VALUE "ENTER STUDENT LAST NAME".
010600         05  LINE 4  COL 37  PIC X(20) TO WS-LNAME.
010700
010800
010900 01  DISPLAY-SCRN.
011000     03  BLANK SCREEN.
011100     03  DISPLAY-REC.
011200         05  LINE 1  COL 01  VALUE "STUDENT INQCITY".
011300         05          COL 73  PIC 9(2) FROM WS-MONTH.
011400         05          COL 75  VALUE "/".
011500         05          COL 76  PIC 9(2) FROM WS-DAY.
011600         05          COL 78  VALUE "/".
011700         05          COL 79  PIC 9(2) FROM WS-YEAR.
011800         05  LINE 2  COL 36  VALUE "STUDENT INQUIRY".
011900         05  LINE 4  COL 4   PIC X(58) FROM  OUT-RECORDS(1).
012000         05  LINE 5  COL 4   PIC X(58) FROM  OUT-RECORDS(2).
012100         05  LINE 6  COL 4   PIC X(58) FROM  OUT-RECORDS(3).
012200         05  LINE 7  COL 4   PIC X(58) FROM  OUT-RECORDS(4).
012300         05  LINE 8  COL 4   PIC X(58) FROM  OUT-RECORDS(5).
012400         05  LINE 9  COL 4   PIC X(58) FROM  OUT-RECORDS(6).
012500         05  LINE 10 COL 4   PIC X(58) FROM  OUT-RECORDS(7).
012600         05  LINE 11 COL 4   PIC X(58) FROM  OUT-RECORDS(8).
012700         05  LINE 12 COL 4   PIC X(58) FROM  OUT-RECORDS(9).
012800         05  LINE 13 COL 4   PIC X(58) FROM  OUT-RECORDS(10).
012900         05  LINE 14 COL 4   PIC X(58) FROM  OUT-RECORDS(11).
013000         05  LINE 15 COL 4   PIC X(58) FROM  OUT-RECORDS(12).
013100         05  LINE 16 COL 4   PIC X(58) FROM  OUT-RECORDS(13).
013200         05  LINE 17 COL 4   PIC X(58) FROM  OUT-RECORDS(14).
013300         05  LINE 18 COL 4   PIC X(58) FROM  OUT-RECORDS(15).
013400         05  LINE 19 COL 4   PIC X(58) FROM  OUT-RECORDS(16).
013500         05  LINE 20 COL 4   PIC X(58) FROM  OUT-RECORDS(17).
013600         05  LINE 21 COL 4   PIC X(58) FROM  OUT-RECORDS(18).
013700         05  LINE 22 COL 4   PIC X(58) FROM  OUT-RECORDS(19).
013800         05  LINE 23 COL 4   PIC X(58) FROM  OUT-RECORDS(20).
013900         05  LINE 25 COL 18  VALUE "PRESS ENTER TO CONTINUE, OR 'X
014000-                                  "' TO EXIT".
014100         05          COL 58  PIC X   TO  WS-CONTINUE AUTO.
014200
014300 01  DISPLAY-EOF-SCRN.
014400     03  BLANK SCREEN.
014500     03  DISPLAY-REC.
014600         05  LINE 1  COL 01  VALUE "STUDENT INQUIRY".
014700         05          COL 73  PIC 9(2) FROM WS-MONTH.
014800         05          COL 75  VALUE "/".
014900         05          COL 76  PIC 9(2) FROM WS-DAY.
015000         05          COL 78  VALUE "/".
015100         05          COL 79  PIC 9(2) FROM WS-YEAR.
015200         05  LINE 2  COL 36  VALUE "STUDENT INQUIRY".
015300         05  LINE 4  COL 4   PIC X(58) FROM  OUT-RECORDS(1).
015400         05  LINE 5  COL 4   PIC X(58) FROM  OUT-RECORDS(2).
015500         05  LINE 6  COL 4   PIC X(58) FROM  OUT-RECORDS(3).
015600         05  LINE 7  COL 4   PIC X(58) FROM  OUT-RECORDS(4).
015700         05  LINE 8  COL 4   PIC X(58) FROM  OUT-RECORDS(5).
015800         05  LINE 9  COL 4   PIC X(58) FROM  OUT-RECORDS(6).
015900         05  LINE 10 COL 4   PIC X(58) FROM  OUT-RECORDS(7).
016000         05  LINE 11 COL 4   PIC X(58) FROM  OUT-RECORDS(8).
016100         05  LINE 12 COL 4   PIC X(58) FROM  OUT-RECORDS(9).
016200         05  LINE 13 COL 4   PIC X(58) FROM  OUT-RECORDS(10).
016300         05  LINE 14 COL 4   PIC X(58) FROM  OUT-RECORDS(11).
016400         05  LINE 15 COL 4   PIC X(58) FROM  OUT-RECORDS(12).
016500         05  LINE 16 COL 4   PIC X(58) FROM  OUT-RECORDS(13).
016600         05  LINE 17 COL 4   PIC X(58) FROM  OUT-RECORDS(14).
016700         05  LINE 18 COL 4   PIC X(58) FROM  OUT-RECORDS(15).
016800         05  LINE 19 COL 4   PIC X(58) FROM  OUT-RECORDS(16).
016900         05  LINE 20 COL 4   PIC X(58) FROM  OUT-RECORDS(17).
017000         05  LINE 21 COL 4   PIC X(58) FROM  OUT-RECORDS(18).
017100         05  LINE 22 COL 4   PIC X(58) FROM  OUT-RECORDS(19).
017200         05  LINE 23 COL 4   PIC X(58) FROM  OUT-RECORDS(20).
017300         05  LINE 25 COL 18  VALUE "END OF FILE, PRESS ENTER TO CO
017400-                                  "NTINUE".
017500         05          COL 58  PIC X   TO  WS-CONTINUE AUTO.
017600
017700 01  DISPLAY-STU-BY-ID-SCRN.
017800     03  BLANK SCREEN.
017900     03  LINE 1  COL 01  VALUE "STUDENT INQUIRY".
018000     03          COL 73  PIC 9(2) FROM WS-MONTH.
018100     03          COL 75  VALUE "/".
018200     03          COL 76  PIC 9(2) FROM WS-DAY.
018300     03          COL 78  VALUE "/".
018400     03          COL 79  PIC 9(2) FROM WS-YEAR.
018500     03  LINE 2  COL 36  VALUE "STUDENT INQUIRY".
018600     03  LINE 3  COL 20  VALUE "STUDENT ID".
018700     03          COL 40  PIC 9(4) FROM IN-STU-ID.
018800     03  LINE 4  COL 20  VALUE "FIRST NAME".
018900     03          COL 40  PIC X(20) FROM IN-FNAME.
019000     03  LINE 5  COL 20  VALUE "LAST NAME".
019100     03          COL 40  PIC X(20) FROM IN-LNAME.
019200     03  LINE 6  COL 20  VALUE "STREET".
019300     03          COL 40  PIC X(30) FROM IN-STREET.
019400     03  LINE 7  COL 20  VALUE "CITY".
019500     03          COL 40  PIC X(5) FROM ZIP-CITY.
019600     03  LINE 8  COL 20  VALUE "STATE".
019700     03          COL 40  PIC X(2) FROM ZIP-STATE.
019800     03  LINE 9  COL 20  VALUE "COUNTY".
019900     03          COL 40  PIC X(30) FROM ZIP-COUNTY.
020000     03  LINE 10 COL 20  VALUE "ZIPCODE".
020100     03          COL 40  PIC X(5) FROM IN-ZIP.
020200     03  LINE 11 COL 20  VALUE "ACTIVE".
020300     03          COL 40  PIC X FROM IN-ACTIVE.
020400     03  LINE 14 COL 32  VALUE "ENTER ANY KEY TO CONTINUE".
020500     03          COL 58  PIC X   TO WS-CONTINUE.
020600
020700 01  ERROR-SCRN.
020800     03  BLANK SCREEN.
020900     03  LINE 12 COL 32 VALUE "ERROR".
021000     03  LINE 14 COL 32 VALUE "FILE STATUS:".
021100     03          COL 46 PIC XX FROM WS-STAT.
021200     03  LINE 16 COL 32 VALUE "ENTER ANY KEY TO CONTINUE".
021300     03          COL 58 PIC X TO WS-CONTINUE AUTO.
021400
021500
021600
021700 PROCEDURE DIVISION.
021800 100-MAIN.
           MOVE ZEROS TO IN-STU-ID

021900     ACCEPT WS-DATE FROM DATE
022000     OPEN INPUT INFILE
022100          INPUT INZIP
022200     DISPLAY INQ-TYPE-SCRN
022300     ACCEPT  INQ-TYPE-SCRN
022400
022500
022600     PERFORM UNTIL WS-INQ-TYPE = 'X' OR 'x'
022700
022800         MOVE SPACES TO WS-LNAME
022900         MOVE ZEROS TO WS-STU-ID
023000
023100         MOVE "N" TO WS-EOF
023200         MOVE 1 TO WS-CNT
023300         MOVE SPACES TO WS-CONTINUE
023400
023500
023600         IF WS-INQ-TYPE = 1
023700             DISPLAY ENTER-STU-ID-SCRN
023800             ACCEPT ENTER-STU-ID-SCRN
023900             MOVE WS-STU-ID TO IN-STU-ID
024000
024100             MOVE "N" TO WS-ERR
024200
024300             START INFILE KEY = IN-STU-ID
024400                 INVALID KEY MOVE "Y" TO WS-ERR
024500             END-START
024600
024700             IF NOT WS-ERR = "Y"
024800
024900                 READ INFILE NEXT RECORD
025000                 END-READ
025100
025200                 MOVE IN-ZIP TO ZIPCODE
025300
025400                 START INZIP KEY = ZIPCODE
025500                 END-START
025600
025700                 READ INZIP NEXT RECORD
025800                 END-READ
025900
026000                 DISPLAY DISPLAY-STU-BY-ID-SCRN
026100                 ACCEPT DISPLAY-STU-BY-ID-SCRN
026200             ELSE
026300                 DISPLAY ERROR-SCRN
026400                 ACCEPT ERROR-SCRN
026500             END-IF
026600         ELSE
026700             DISPLAY ENTER-LNAME-SCRN
026800             ACCEPT ENTER-LNAME-SCRN
026900             MOVE WS-LNAME TO IN-LNAME
027000
027100             START INFILE KEY >= IN-LNAME
027200             END-START
027300
027400             PERFORM 200-DISPLAY
027500
027600         END-IF
027700
027800         DISPLAY INQ-TYPE-SCRN
027900         ACCEPT  INQ-TYPE-SCRN
028000     END-PERFORM
028100     CLOSE INFILE
028200     CLOSE INZIP
028300
028400     EXIT PROGRAM.
028500
028600 200-DISPLAY.
028700     PERFORM UNTIL ((WS-EOF = "Y") OR
028800     ((WS-CONTINUE = "X" OR WS-CONTINUE = "x") AND WS-EOF = "N"))
028900         PERFORM 300-INIT-ARRAY
029000         PERFORM 400-READ-INPUT
029100         IF WS-EOF = "Y"
029200             DISPLAY DISPLAY-EOF-SCRN
029300             ACCEPT DISPLAY-EOF-SCRN
029400         ELSE
029500             DISPLAY DISPLAY-SCRN
029600             ACCEPT DISPLAY-SCRN
029700         END-IF
029800     END-PERFORM.
029900
030000 300-INIT-ARRAY.
030100     MOVE 1 TO WS-LOOP-CNT
030200     PERFORM UNTIL WS-LOOP-CNT > 20
030300         MOVE SPACES TO OUT-RECORDS(WS-LOOP-CNT)
030400         ADD 1 TO WS-LOOP-CNT
030500     END-PERFORM.
030600
030700 400-READ-INPUT.
030800     READ INFILE NEXT RECORD
030900         AT END MOVE 'Y' TO WS-EOF
031000     END-READ
031100     MOVE 1 TO WS-LOOP-CNT
031200     PERFORM UNTIL WS-LOOP-CNT > 20 OR WS-EOF = "Y"
031300         MOVE WS-CNT         TO OUT-NO(WS-LOOP-CNT)
031400         MOVE IN-STU-ID      TO OUT-STU-ID(WS-LOOP-CNT)
031500         MOVE IN-FNAME       TO OUT-FNAME(WS-LOOP-CNT)
031600         MOVE IN-LNAME       TO OUT-LNAME(WS-LOOP-CNT)
031700         MOVE IN-ZIP         TO OUT-ZIP(WS-LOOP-CNT)
031800         MOVE IN-ACTIVE      TO OUT-ACTIVE(WS-LOOP-CNT)
031900
032000         READ INFILE NEXT RECORD
032100             AT END MOVE 'Y' TO WS-EOF
032200         END-READ
032300         ADD 1 TO WS-LOOP-CNT
032400         IF WS-CNT = 999
032500             MOVE 1 TO WS-CNT
032600         ELSE
032700             ADD 1 TO WS-CNT
032800         END-IF
032900     END-PERFORM.
033000
